field.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from 'classnames'
  5. type Props = {
  6. className?: string
  7. label: string
  8. labelClassName?: string
  9. value: string | number
  10. onChange: (value: string) => void
  11. isRequired?: boolean
  12. placeholder?: string
  13. }
  14. const Field: FC<Props> = ({
  15. className,
  16. label,
  17. labelClassName,
  18. value,
  19. onChange,
  20. isRequired = false,
  21. placeholder = '',
  22. }) => {
  23. return (
  24. <div className={cn(className)}>
  25. <div className='flex py-[7px]'>
  26. <div className={cn(labelClassName, 'flex items-center h-[18px] text-[13px] font-medium text-gray-900')}>{label} </div>
  27. {isRequired && <span className='ml-0.5 text-xs font-semibold text-[#D92D20]'>*</span>}
  28. </div>
  29. <input
  30. type='text'
  31. value={value}
  32. onChange={e => onChange(e.target.value)}
  33. className='flex h-9 w-full py-1 px-2 rounded-lg text-xs leading-normal bg-gray-100 caret-primary-600 hover:bg-gray-100 focus:ring-1 focus:ring-inset focus:ring-gray-200 focus-visible:outline-none focus:bg-gray-50 placeholder:text-gray-400'
  34. placeholder={placeholder}
  35. />
  36. </div>
  37. )
  38. }
  39. export default React.memo(Field)